#include "movielistitemwidget.h"
#include "ui_movielistitemwidget.h"
#include <QTime>

MovieListItemWidget::MovieListItemWidget(QWidget *parent) :
	QWidget(parent),
	ui(new Ui::MovieListItemWidget)
{
	SetUp(QString(""),0, QStringList(), 0, 0, 0 );
}
MovieListItemWidget::MovieListItemWidget(const QString &title, QWidget *parent) :
	QWidget(parent),
	ui(new Ui::MovieListItemWidget)
{
	SetUp(title,0, QStringList(), 0, 0, 0 );
}
MovieListItemWidget::MovieListItemWidget(const QString &title, const int year, const QStringList &genres,
										 const int imdbRating, const int personalRating, const int lengthInSeconds, QWidget *parent):
	QWidget(parent),
	ui(new Ui::MovieListItemWidget)
{
	SetUp(title, year, genres, imdbRating, personalRating, lengthInSeconds);
}

void MovieListItemWidget::SetUp(const QString &title, const int year, const QStringList &genres,
								const int imdbRating, const int personalRating, const int lengthInSeconds)
{
	ui->setupUi(this);
	SetMovie(title, year, genres, imdbRating, personalRating, lengthInSeconds);
}

void MovieListItemWidget::SetMovie(QString title, int year, QStringList genres, int imdbRating, int personalRating, int lengthInSeconds)
{
	SetMovieTitle(title);
	SetMovieYear(year);
	SetMovieGenre(genres);
	SetMovieIMDBRating(imdbRating);
	SetMoviePersonalRating(personalRating);
	SetMovieLength(lengthInSeconds);
}

void MovieListItemWidget::SetMovieTitle(const QString &title)
{
	this->Title = title;
	ui->movieTitle->setText(Title);
}

void MovieListItemWidget::SetMovieYear(const int year)
{
	this->Year = year;
	ui->movieYear->setText(QString("(%1)").arg(year));
}

void MovieListItemWidget::SetMovieGenre(const QStringList &genres)
{
	this->Genre = genres;

	QString displayGenre;
	for(int i = 0; i < genres.length(); i++)
	{
		if(i != 0)
			displayGenre.append(tr(", "));

		displayGenre.append(genres[i]);
	}
}

void MovieListItemWidget::SetMovieIMDBRating(const int rating)
{
	this->IMDBRating = rating;

	QString displayRating(tr("IMDB: "));
	for(int i = 0; i < rating; i++)
	{
		displayRating.append(tr("*"));
	}
}

void MovieListItemWidget::SetMoviePersonalRating(const int rating)
{
	this->PersonalRating = rating;

	QString displayRating(tr("Personal: "));
	for(int i = 0; i < rating; i++)
	{
		displayRating.append(tr("*"));
	}
}
void MovieListItemWidget::SetMovieLength(const int seconds)
{
	this->Length = seconds;

	QTime time(0, 0, seconds);
	ui->movieLength->setText(time.toString(tr("'Length:' h:mm")));
}

MovieListItemWidget::~MovieListItemWidget()
{
	//delete ui;
}
